package com.zztl.infiniteBand.presenter

import android.app.Activity
import android.content.ClipboardManager
import android.content.Context
import android.text.TextUtils
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.AddressBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.GetWalletAddrRequest
import com.zztl.infiniteBand.ui.view.mvpview.IncomeView
import com.zztl.infiniteBand.util.UiUtils
import com.zztl.infiniteBand.util.toast


/**
 * @desc
 * @auth ${user}
 * @time 2018/6/13  17:57
 */
class IncomePresenter : BasePresenter<IncomeView>() {
    fun copyAddress(address: String, activity: Activity) {
        if (!TextUtils.isEmpty(address)) {
            val cbManager = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            cbManager.text = address
            UiUtils.context.toast(UiUtils.getString(R.string.地址已复制到剪贴板))
        }
    }

    fun getAddress(request: GetWalletAddrRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getWalletAddress(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber<AddressBean>(context) {
                    override fun success(bean: AddressBean) {
                        view!!.getAddrSuccess(bean)

                    }

                }))
    }
}
